package com.lhj.springboot.web.handler;

import com.alibaba.fastjson2.JSON;
import com.fasterxml.jackson.databind.util.JSONPObject;
import jakarta.servlet.ServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.function.ServerRequest;
import org.springframework.web.servlet.function.ServerResponse;

import java.util.Map;

/**
 * @Description
 * @Author lhj
 * @Date 2024/6/19 22:22
 */
@Slf4j
@Component
public class UserHandler {
    
    public ServerResponse getUser() {
        return ServerResponse.ok().build();
    }
    
    public ServerResponse getUsers() {
        log.info("getUsers");
        return ServerResponse.ok().body("getUsers");
    }
    
    public ServerResponse addUser(ServletRequest request) {
        Map<String, String[]> parameterMap = request.getParameterMap();
        log.info("保存用户信息：{}", JSON.toJSONString(parameterMap));
        return ServerResponse.ok().body("getUserById");
    }

    public ServerResponse getUser(ServerRequest serverRequest)  {
        String userId = serverRequest.pathVariable("id");
        log.info("获取用户 userId: {}", userId);
        return ServerResponse.ok().body("getUser");
    }
}
